package com.example.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.common.Result;
import com.example.entity.Feedback;
import com.example.service.FeedbackService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@Tag(name = "反馈管理接口")
@RestController
@RequestMapping("/api/feedbacks")
@RequiredArgsConstructor
public class FeedbackController {

    private final FeedbackService feedbackService;

    @Operation(summary = "提交反馈")
    @PostMapping("/submit")
    public Result<Boolean> submit(@RequestBody Feedback feedback) {
        return Result.success(feedbackService.submitFeedback(feedback));
    }

    @Operation(summary = "回复反馈")
    @PostMapping("/{id}/reply")
    public Result<Boolean> reply(
            @Parameter(description = "反馈ID") @PathVariable Long id,
            @Parameter(description = "回复内容") @RequestParam String reply,
            @Parameter(description = "回复人ID") @RequestParam Long replyUserId) {
        return Result.success(feedbackService.replyFeedback(id, reply, replyUserId));
    }

    @Operation(summary = "更新反馈状态")
    @PostMapping("/{id}/status")
    public Result<Boolean> updateStatus(
            @Parameter(description = "反馈ID") @PathVariable Long id,
            @Parameter(description = "状态：0-待处理 1-处理中 2-已处理 3-已关闭") @RequestParam Integer status) {
        return Result.success(feedbackService.updateStatus(id, status));
    }

    @Operation(summary = "删除反馈")
    @DeleteMapping("/{id}")
    public Result<Boolean> delete(@Parameter(description = "反馈ID") @PathVariable Long id) {
        return Result.success(feedbackService.deleteFeedback(id));
    }

    @Operation(summary = "批量删除反馈")
    @DeleteMapping("/batch")
    public Result<Boolean> batchDelete(@Parameter(description = "反馈ID数组") @RequestBody Long[] ids) {
        return Result.success(feedbackService.batchDeleteFeedbacks(ids));
    }

    @Operation(summary = "分页查询反馈列表")
    @GetMapping("/list")
    public Result<Page<Feedback>> list(
            @Parameter(description = "页码") @RequestParam(defaultValue = "1") Integer pageNum,
            @Parameter(description = "每页数量") @RequestParam(defaultValue = "10") Integer pageSize,
            @Parameter(description = "用户ID") @RequestParam(required = false) Long userId,
            @Parameter(description = "反馈类型") @RequestParam(required = false) Integer type,
            @Parameter(description = "反馈状态") @RequestParam(required = false) Integer status) {
        return Result.success(feedbackService.getFeedbackList(pageNum, pageSize, userId, type, status));
    }

    @Operation(summary = "获取反馈详情")
    @GetMapping("/{id}")
    public Result<Feedback> getInfo(@Parameter(description = "反馈ID") @PathVariable Long id) {
        return Result.success(feedbackService.getFeedbackInfo(id));
    }
} 